<?php
/*******************************************
* Orain 入口文件
* 初始化相关操作
******************************************/
error_reporting(E_ALL ^ E_NOTICE);
define('IN_ORA','true');
//设置时区
date_default_timezone_set('PRC');
// 0 为调试模式, 1 为正式运行模式
$GLOBALS['RUN_MODEL'] = 0;
//程序路径
define('ROOT_PATH', str_replace("\\", "/", dirname(__FILE__)) . '/');
//程序Url
define('HTTP_HOST',array_shift(explode("/index.php","http://".$_SERVER["HTTP_HOST"].$_SERVER['SCRIPT_NAME'])));
//HTML文件目录
define('ARCHIVE_PATH',ROOT_PATH."archive/");
//上传目录
define('UPLOAD_PATH',ROOT_PATH."upload/");
//缓存目录
define('CACHE_PATH',ROOT_PATH."cache/");
//标记时间
$GLOBALS['startdateline'] = microtime();
//加载配置文件
$GLOBALS["ora_cfg"] = include_once(ROOT_PATH."config/config.php");
//模板路径
define('TPL_PATH',ROOT_PATH."themes/".$GLOBALS["ora_cfg"]["themes"]."/");
//加载系统类库
if(!file_exists(ROOT_PATH.'cache/~runtime.php')){
	$s = file_get_contents(ROOT_PATH."source/base.class.php");
	$s .= file_get_contents(ROOT_PATH."source/io.class.php");
	$s .= file_get_contents(ROOT_PATH."source/cache.class.php");
	$s .= file_get_contents(ROOT_PATH."source/tpl.class.php");
	$s .= file_get_contents(ROOT_PATH."source/".$GLOBALS["ora_cfg"]["db_driver"].".class.php");
	$s .= file_get_contents(ROOT_PATH."common.php");
	if(!is_dir(CACHE_PATH)){
		mkdir(CACHE_PATH);
	}
	file_put_contents(ROOT_PATH.'cache/~runtime.php',$s);
	if($GLOBALS['RUN_MODEL'] == '1'){
		file_put_contents(ROOT_PATH.'cache/~runtime.php',php_strip_whitespace(ROOT_PATH.'cache/~runtime.php'));
	}
}
include_once(ROOT_PATH.'cache/~runtime.php');
//计时
$GLOBALS['__STARTTIME__'] = microtime_float();
$GLOBALS["__QUERY__"] = 0;
//实例化模板操作对象
$GLOBALS["tpl"] = new tpl(ROOT_PATH."cache/template/",$GLOBALS["ora_cfg"]["cache_time"],$GLOBALS["ora_cfg"]["mk_html"],($GLOBALS['ora_cfg']['data_cache']>0));
//实例化数据库操作对象
$dbclsname =$GLOBALS["ora_cfg"]["db_driver"];
$GLOBALS['db'] = new $dbclsname;
//路由解析
orain_router(intval($GLOBALS["ora_cfg"]["router"]));
//访问控制
if(in_array($GLOBALS["mod"],$GLOBALS["ora_cfg"]['acs'])){
	if(is_file(ROOT_PATH."module/".$GLOBALS["mod"]."_mod.php")){
		if(!get_magic_quotes_gpc()){
			$_GET     = addslashes_deep($_GET);
			$_POST    = addslashes_deep($_POST);
			$_REQUEST = addslashes_deep($_REQUEST);
		}
		include_once(ROOT_PATH."module/".$GLOBALS["mod"]."_mod.php");
	}else{
		throwException("模块 ".$GLOBALS["mod"]." 未找到! ",__file__,__line__);
	}
}else{
	throwException("未授权的请求!",__file__,__line__);
}
?>